home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Magazine 28 Bonus / CDRomMagazine-SoftKey-ArtPassion-FrenchVersion-Win31Mac.bin / data / pvtecpl.dir / 00092_Script_GAME HANDLERS < prev    next >
Text File  |  1996-06-16  |  8KB  |  314 lines

  1. on startMovie
  2.   
  3.   
  4.   
  5. end
  6.  
  7.  
  8. on initializePerspectiveGame
  9.   
  10.   
  11.   global ObjectsFixedList,moveSprite,numberOfPieces
  12.   global gridlineButtonOff,gridlineButtonOn,endNarration,gameOverNarration,bad
  13.   
  14.   set numberOfPieces = 19
  15.   set moveSprite = 25
  16.   set gridlineButtonOn = 32
  17.   set gridlineButtonOff = 31
  18.   set bad = 10
  19.   
  20.   -- name of the .AIFF that is called when all objects are at their correct positions
  21.   set endNarration = "success"
  22.   
  23.   
  24.   
  25.   
  26.   puppetSprite moveSprite,TRUE
  27.   removeFromStage(moveSprite)
  28.   
  29.   set ObjectsFixedList = []
  30.   global PerspectiveInfo,gridlines,moveSprite,firstPiece,lastPiece
  31.   global placedObjects
  32.   
  33.   setpuppets 4,22,TRUE
  34.   
  35.   set PerspectiveInfo = field "Perspective Locations"
  36.   set gridlines = 24
  37.   set firstPiece = 4
  38.   set lastPiece = 22
  39.   set placedObjects = [easel2:0,booksshelf:0,bowlbottom:0,carpet:0,box:0,easel1:0,globe:0,clock:0,table:0,cup:0,¼
  40. booktable:0,MiddleBowl:0,TopBowl:0,statue:0,candle:0,skull:0,boxcupboard:0,material:0,¼
  41. cupboardDoor:0]
  42.   
  43.   put 0 into field "totalplaced"
  44.   
  45.   when mouseDown then dragObject(the clickOn)
  46.   
  47. end
  48.  
  49.  
  50. on dragObject aSprite
  51.   global objectsFixedList,moveSprite,firstPiece,lastPiece
  52.   
  53.   if (aSprite > firstPiece - 1) AND (aSprite <= lastPiece) then
  54.     switchBackPlaced (aSprite)
  55.     switchMoveSprites(aSprite)
  56.     removeFromStage(aSprite)
  57.     track aSprite
  58.     if allPlaced() then
  59.       waitticks 60
  60.       playEnd
  61.     end if
  62.   end if
  63.   
  64. end
  65.  
  66.  
  67. -- if the sprite is already placed in the correct position, castmnembers have to be changed and
  68. -- the counter "total sprites that are in position" should be adjusted
  69. on switchBackPlaced whichSprite
  70.   
  71.   set nameofCast = the name of cast the castNum of sprite whichSprite
  72.   if nameofCast contains "PLACED" then
  73.     set newName = word 1 of nameofCast
  74.     set the castNum of sprite whichSprite = the number of cast newName
  75.     setSizeFigures(whichSprite,NewName)
  76.     
  77.   end if
  78.   
  79. end
  80.  
  81.  
  82. -- switch the (empty) castmember of the sprite that is used to move the clicked sprite¼
  83. -- (moveSprite) to the castmember of the object 
  84. on switchMoveSprites whichSprite
  85.   global moveSprite
  86.   set the castNum of sprite moveSprite = the castNum of sprite whichSprite
  87.   set the locH of sprite moveSprite = the mouseH
  88.   set the locV of sprite moveSprite = the mouseV
  89.   updateStage
  90. end
  91.  
  92.  
  93. -- handler MatchHandler gets executed when the object is placed in
  94. -- it's right  position
  95. on matchHandler ClickedSprite
  96.   global sectionName, sectionRect,marker,objectsFixedList
  97.   
  98.   
  99.   if marker = 1 then -- change cast to it's "placed" version
  100.     set the castNum of sprite ClickedSprite = the number of cast ¼
  101. (sectionName && "Placed")
  102.   end if
  103.   
  104.   snapToPoint(ClickedSprite)
  105.   updateStage
  106.   
  107.   puppetSound "correct"
  108.   updateStage
  109.   --    waitTicks 60
  110.   --    puppetSound 0
  111.   
  112.   
  113.   -- sound playFile 1, the pathname & "PVtecPLA:Correct.aif"
  114.   
  115. end
  116.  
  117.  
  118. -- handler snapToPoint sets the coordinates of the clicked sprite (NOT the movesprite!)
  119. -- so that it is visible on the stage
  120. on snapToPoint whichSprite
  121.   global sectionRect
  122.   
  123.   spriteBox whichSprite, rectLeft(sectionRect), rectTop(sectionRect), ¼
  124. rectRight(sectionRect), rectBottom(sectionRect)
  125.   
  126. end
  127.  
  128.  
  129. on addObjectToList anObject
  130.   global placedObjects
  131.   -- set the value of <object> in the list to 1
  132.   
  133.   setaProp placedObjects,anObject,1
  134.   
  135. end
  136.  
  137.  
  138. -- handler deleteObjectFromList deletes an object from a string
  139. on deleteObjectFromList anObject
  140.   global placedObjects
  141.   -- set the value of <object> in the list to 0
  142.   setaProp placedObjects,anObject,0
  143.   
  144. end
  145.  
  146.  
  147. -- handler checkTotalPlaced checks how many objects are positioned correct.It calls handler
  148. -- playEndNarration when all is positioned.
  149. on allPlaced
  150.   global placedObjects,numberOfPieces,objectsPlaced
  151.   set objectsPlaced = 0
  152.   
  153.   repeat with i = 1 to count(placedObjects)
  154.     if getAt(placedObjects,i) = 1 then set objectsPlaced = objectsPlaced + 1
  155.   end repeat
  156.   
  157.   put objectsPlaced into field "totalPlaced"
  158.   
  159.   if objectsPlaced = numberOfPieces then return TRUE
  160.   
  161. end
  162.  
  163.  
  164. on setSizeFigures whichSprite,NewName
  165.   put the text of cast "sizeMoveFigures" into sizeInfo
  166.   repeat with i = 1 to the number of lines in sizeInfo
  167.     set figureMove = item 1 of line i of sizeInfo
  168.     if figureMove = NewName then
  169.       put value(item 2 of line i of sizeInfo)
  170.       
  171.       set the width of sprite whichSprite = value(item 2 of line i of sizeInfo)
  172.       set the height of sprite whichSprite =value(item 3 of line i of sizeInfo)
  173.     end if
  174.   end repeat
  175. end
  176.  
  177.  
  178. on track ClickedSprite
  179.   global gameOver,moveSprite
  180.   
  181.   -- drag the piece while the mouse is down
  182.   repeat while the stillDown
  183.     SpriteFollowMouse(moveSprite)
  184.     if timeElapsed() then
  185.       exit repeat
  186.       playGameOver
  187.     end if
  188.   end  repeat  
  189.   
  190.   -- the mouse is now Up, ie. the user placed the piece somewhere
  191.   -- check if the piece was placed in the right place
  192.   removeFromStage(moveSprite)
  193.   set objectPlaced = the name of cast (the castNum of sprite ClickedSprite)
  194.   
  195.   if checkhandler() then
  196.     matchHandler(ClickedSprite)
  197.     addObjectToList objectPlaced -- mark object as placed
  198.   else
  199.     set the locH of sprite ClickedSprite = the mouseH
  200.     set the locV of sprite ClickedSprite = the mouseV
  201.     updateStage
  202.     deleteObjectFromList objectPlaced -- mark object as NOT placed
  203.   end if
  204.   
  205. end
  206.  
  207.  
  208. -- Handler checkHandler returns TRUE if the user placed the
  209. -- outline in the proper place and FALSE otherwise.
  210.  
  211. on checkHandler
  212.   global PerspectiveInfo, sectionName, sectionRect,marker
  213.   set sectionRect = 0
  214.   
  215.   repeat with i = 1 to the number of lines in PerspectiveInfo
  216.     set lineInfo = line i of PerspectiveInfo
  217.     set sectionName = item 1 of lineInfo 
  218.     if the name of cast the castNum of sprite the clickOn = sectionName then 
  219.       set leftP = value(item 2 of lineInfo)
  220.       set topP = value(item 3 of lineInfo)
  221.       set rightP =value( item 4 of lineInfo)
  222.       set bottomP =value(item 5 of lineInfo)
  223.       set sectionRect = rect(leftP,topP,rightP,bottomP)
  224.       set marker = value(item 6 of lineInfo)
  225.       exit repeat
  226.     end if
  227.   end repeat
  228.   
  229.   if  (inside(point(the mouseH,the mouseV), sectionRect)) then return TRUE
  230.   
  231. end
  232.  
  233.  
  234. on spriteFollowMouse whichSprite
  235.   -- move the piece with the mouse
  236.   set the locH of sprite whichSprite = the mouseH
  237.   set the locV of sprite whichSprite = the mouseV
  238.   updateStage
  239.   
  240. end
  241.  
  242.  
  243. -- set up the playButton in the lower right corner
  244. on setUpPlayButton
  245.   puppetSprite 33,TRUE
  246.   set the castNum of sprite 33 = the number of cast "PlayButton extended"
  247.   updateStage
  248. end
  249.  
  250.  
  251. on setUpGridLinesButton
  252.   global gridlines
  253.   set gridlines = 24
  254.   
  255. end
  256.  
  257.  
  258. -- handler playButton switches the castmember of the clicked sprite. In this
  259. -- case the playbutton switches between a pressed and non-pressed state.
  260. on playButton aSprite
  261.   if the name of cast (the castNum of sprite aSprite) = "PlayButton Extended" then
  262.     set the castNum of sprite aSprite = the number of cast "PlayButton Pushed"
  263.   else
  264.     set the castNum of sprite aSprite = the number of cast "PlayButton Extended"
  265.   end if
  266.   --  updateStage
  267.   --  puppetSound "Start Game"
  268.   --  updateStage
  269.   --  waitTicks 180
  270.   --  puppetSound 0
  271.   set the castNum of sprite aSprite to the number of cast "empty button"
  272.   updateStage
  273.   
  274. end
  275.  
  276.  
  277. on deleteLabel aSprite
  278.   set the castNum of sprite aSprite to 0
  279.   updateStage
  280.   
  281. end
  282.  
  283.  
  284. on playEnd
  285.   global endNarration
  286.   puppetSound endNarration
  287.   waitSound 1
  288.   go "PVtecPlSt1"
  289.   
  290. end
  291.  
  292.  
  293. on playGameOver
  294.   global gameOverNarration,objectsPlaced,bad
  295.   if objectsPlaced < bad then
  296.     set gameOverNarration = "bad"
  297.   else
  298.     set gameOverNarration = "good"
  299.   end if
  300.   
  301.   puppetSound gameOverNarration
  302.   waitSound 1
  303.   go "PVtecPlSt1"
  304.   
  305. end
  306.  
  307.  
  308. on setpuppets startSprite,endSprite,state
  309.   repeat with i = startSprite to endSprite
  310.     puppetSprite i,state
  311.   end repeat
  312.   
  313. end
  314.